package org.enhance.async.init.service;

import lombok.extern.slf4j.Slf4j;
import org.basis.enhance.async.init.annotation.BasisAsyncInit;

import java.util.concurrent.TimeUnit;

/**
 * hello service
 *
 * @author wenpan 2023/06/11 22:26
 */
@Slf4j
@BasisAsyncInit
public class HelloService {

    /**
     * init方法
     */
    public void init() throws InterruptedException {
        log.info("i am HelloService.init method, start........");
        // 睡一会儿，这里模拟初始化方法非常耗时，初始化方法执行完毕前容器不允许正常启动成功
        TimeUnit.SECONDS.sleep(10);
        // 这里模拟异步初始化失败容器不允许正常启动
//        final int i = 1 / 0;
        log.info("i am HelloService.init method, end........");
    }

    public String sayHello(String name) {
        log.info("hello {}", name);
        return "hello-" + name;
    }
}
